<?php
namespace Core\Event;

use Phalcon\Di\Injectable;

class View extends Injectable
{

    private $_profiler;

    public function __construct() {
        if($this->di->has('profiler')) {
            $this->_profiler = $this->profiler;
        }
    }

    /**
     * Before view render
     * @param Event object.
     * @param View object.
     * @return $this
     */
    public function beforeRender($event, $view) {
        if ($this->_profiler) {
            $this->_profiler->start();
        }
        return true;
    }

    //after render
    public function afterRender($event, $view, $file){
        if ($this->_profiler) {
            $this->_profiler->stop($view->getActiveRenderPath(), 'view');
        }
        return true;
    }

    //not found view
    public function notFoundView($event, $view, $file) {
        //throw new \Exception("View not found - {$file}");
        return true;
    }
}